<!--
 * @LastEditors: 杜康
 * @LastEditTime: 2021-09-15 18:31:01
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>简易聊天室</title>
</head>

<body>
  <div id="app">
    <ele></ele>
  </div>
  <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
  <script>
    Vue.component('ele', {
      render: function (createElement) {
        var _this = this
        if (this.list.length) {
          var listNode = createElement('ul', this.list.map(function (item) {
            return createElement('li', item)
          }))
        } else {
          var listNode = createElement('p', '暂无聊天内容')
        }
        return createElement('div', [
          listNode,
          createElement('input', {
            attrs: {
              placeholder: '请输入内容，按回车键发送'
            },
            style: {
              width: '200px'
            },
            on: {
              keyup: function (e) {
                if (e.code === 'Enter') {
                  _this.list.push(e.target.value)
                } else {
                  return
                }
                e.target.value = ''
              }
            }
          })
        ])
      },
      data: function () {
        return {
          value: '',
          list: []
        }
      }
    })

    var app = new Vue({
      el: '#app'
    })
  </script>
</body>

</html>